<template>
  <div>
    <el-row>
      <el-col :span="24">
        <div class="clearfix" style="background-color: white;margin:20px;">
          <div style="margin:20px;">
            <div>
              <span>项目信息</span>
              <el-button type="danger" icon="el-icon-delete" size="small" style="float: right"
              v-if="isUpdate" @click="deleteProjects"></el-button>
            </div>
            <div style="float: left;width: 30%;">
              <p>项目负责人</p>
              <p slot="reference"v-show="principal_open == 0">
                <el-avatar style="float:left; margin-top:3px;" size="small" :src="projectDetail.principalHead" v-if="projectDetail.principalHead != '无'"></el-avatar>
                <span style="cursor: pointer;float:left;margin-top: 6px;" @click="openPrincipal">{{projectDetail.principalName}}</span>
              </p>
              <el-select v-model="projectDetail.principalId"  filterable placeholder="请选择" v-show="principal_open == 1" size="small"
                         @blur="principal_open = 0" @change="updatePrincipal($event)" ref="principal" style="width: 120px;">
                <el-option
                  v-for="item in members"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                  <el-avatar style="float:left; margin-top:3px;" size="small" :src="item.circleUrl"></el-avatar>
                  <span style="float:left;margin-left: 5px;">{{ item.label }}</span>
                </el-option>
              </el-select>
            </div>
            <div style="float: left;width: 30%">
              <p>项目开始时间</p>
              <p  slot="reference"v-show="start_open == 0">
                  <span style="cursor: pointer" @click="openStart" v-if="projectDetail.start != ''">{{projectDetail.start}}</span>
                <span style="cursor: pointer" @click="openStart" v-if="projectDetail.start == ''">无</span>
              </p>
              <el-date-picker
                v-model="projectDetail.start"
                type="datetime"
                placeholder="选择日期时间"
                align="right"
                size="small"
                :editable="false"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                :picker-options="pickerOptions"
                v-show="start_open == 1"
                @blur="start_open = 0"
                @change="updateStartDate"
                ref="start"
                style="width: 90%">
              </el-date-picker>
            </div>
            <div style="float: left;width: 30%">
              <p>项目截止日期</p>
              <p  slot="reference"v-show="over_open == 0">
                <span style="cursor: pointer" @click="openOver" v-if="projectDetail.over != ''">{{projectDetail.over}}</span>
                <span style="cursor: pointer" @click="openOver" v-if="projectDetail.over == ''">无</span>
              </p>
              <el-date-picker
                v-model="projectDetail.over"
                type="datetime"
                placeholder="选择日期时间"
                align="right"
                size="small"
                :editable="false"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                :picker-options="pickerOptions"
                v-show="over_open == 1"
                @blur="over_open = 0"
                @change="updateOverDate"
                ref="over"
                style="width: 90%;margin-bottom: 5px;">
              </el-date-picker>
            </div>
            <div style="float: left;width: 30%;margin-top: 15px">
              <p>当前状态</p>
              <p  slot="reference"v-show="status_open == 0"><span style="cursor: pointer" @click="openStatus">{{projectDetail.status}}</span></p>
              <el-select v-model="projectDetail.status" placeholder="请选择" v-show="status_open == 1" size="small"
                         @blur="status_open = 0" @change="updateStatus" ref="status" style="width: 25%;margin-bottom:1px;">
                <el-option
                  v-for="item in status"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
            <div style="float: left;width: 30%;margin-top: 15px">
              <p>可见范围</p>
              <p  slot="reference"v-show="rouge_open == 0">
                <span style="cursor: pointer" @click="openRouge">{{projectDetail.Scope}}</span>
              </p>
              <el-select v-model="projectDetail.rouge" placeholder="请选择" v-show="rouge_open == 1" size="small"
                         @blur="rouge_open = 0" @change="updateRouge" ref="rouge" style="width: 70%;margin-bottom:5px;">
                <el-option
                  v-for="item in scope"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
            <div style="float: left;width: 20%;margin-top: 20px">
              <p>项目编号</p>
              <p style="cursor: pointer;font-size: 15px" v-show="number_open == 0" @click="openNumber">{{projectDetail.number}}</p>
              <el-input type="text" v-model.trim="projectDetail.number" style="width: 100%;margin-bottom:1px" size="small" v-show="number_open == 1"  @blur="updateProjectName" ref="number"></el-input>
            </div>
            <div style="float: left;width: 30%;margin-top: 15px">
              <p>项目类型：</p>
              <p  slot="reference"v-show="type_open == 0"><span style="cursor: pointer" @click="openType">{{projectDetail.type}}</span></p>
              <el-select v-model="projectDetail.type" placeholder="请选择" v-show="type_open == 1" size="small"
                         @blur="type_open = 0" @change="updateType" ref="type" style="width: 35%;margin-bottom:1px;">
                <el-option
                  v-for="item in type"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
            <div style="float: left;width: 30%;margin-top: 15px">
              <p>客户单位：</p>
              <p style="cursor: pointer;font-size: 15px" v-show="unit_open == 0" @click="openUnit">{{projectDetail.unit}}</p>
              <p style="cursor: pointer;font-size: 15px" v-show="unit_open == 0" @click="openUnit" v-if="projectDetail.unit == ''">无</p>
              <el-input type="text" v-model.trim="projectDetail.unit" style="width: 90%;margin-bottom:1px" size="small" v-show="unit_open == 1"  @blur="updateUnit" ref="unit"></el-input>
            </div>
            <div style="float: left;width: 30%;margin-top: 15px">
              <p>客户代表：</p>
              <p style="cursor: pointer;font-size: 15px" v-show="representative_open == 0" @click="openRepresentative">{{projectDetail.representative}}</p>
              <p style="cursor: pointer;font-size: 15px" v-show="representative_open == 0" @click="openRepresentative" v-if="projectDetail.representative == ''">无</p>
              <el-input type="text" v-model.trim="projectDetail.representative" style="width: 90%;margin-bottom:1px" size="small" v-show="representative_open == 1"  @blur="updateRepresentative" ref="representative"></el-input>
            </div>
            <div style="float: left;width: 100%;margin-top: 15px">
              <p>参与人：</p>
              <el-select v-model="projectDetail.member" multiple filterable placeholder="请选择成员" class="selectStyle" :disabled="!isUpdate"
              @change="updateMembers">
                <el-option
                  v-for="item in members"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                  <el-avatar style="float:left; margin-top:3px;" size="small" :src="item.circleUrl"></el-avatar>
                  <span style="float:left;margin-left: 5px;">{{ item.label }}</span>
                </el-option>
              </el-select>
            </div>
            <div style="float: left;width: 100%;margin-top: 15px">
              <p>状态描述：</p>
              <p  slot="reference">
                <span style="cursor: pointer" v-show="statusDes_open == 0" @click="openStatusDes" v-if="projectDetail.statusDes != ''">{{projectDetail.statusDes}}</span>
                <span style="cursor: pointer" v-show="statusDes_open == 0" @click="openStatusDes" v-else="projectDetail.statusDes == ''">无</span>
              </p>
              <el-input
                type="textarea"
                placeholder="评论内容，文字上限2000"
                v-model="projectDetail.statusDes"
                :value="projectDetail.statusDes"
                maxlength="2000"
                show-word-limit
                resize="none"
                rows="3"
                v-show="statusDes_open == 1"
                ref="statusDes"
              >
              </el-input>
              <div style="margin-top: 10px;" v-show="statusDes_open == 1">
                <el-button type="primary" size="mini" @click.native="updateStatusDes">保存</el-button>
                <el-button size="mini" @click.native="cancelStatusDes">取消</el-button>
              </div>
            </div>
            <div style="float: left;width: 100%;margin: 15px 0;">
              <p>项目描述：</p>
              <p  slot="reference">
                <span style="cursor: pointer" v-show="description_open == 0" @click="openDescription" v-if="projectDetail.description != ''">{{projectDetail.description}}</span>
                <span style="cursor: pointer" v-show="description_open == 0" @click="openDescription" v-else="projectDetail.description == ''">无</span>
              </p>
              <el-input
                type="textarea"
                placeholder="评论内容，文字上限2000"
                v-model="projectDetail.description"
                :value="projectDetail.description"
                maxlength="2000"
                show-word-limit
                resize="none"
                rows="3"
                v-show="description_open == 1"
                ref="description"
              >
              </el-input>
              <div style="margin-top: 10px;" v-show="description_open == 1">
                <el-button type="primary" size="mini"  @click="updateDes">保存</el-button>
                <el-button size="mini"  @click.native="cancelDes">取消</el-button>
              </div>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <div style="background-color: white;margin:0 20px;padding:10px 20px;text-align: center" class="clearfix">
          <p>任务进度</p>
          <div style="float: left;width:50%;margin-top: 10px;">
            <el-progress type="dashboard" :percentage="missionComplete" :color="missionCompleteColors"></el-progress>
            <p>完成率</p>
          </div>
          <div style="float: left;width:50%;margin-top: 10px;">
            <el-progress type="dashboard" :percentage="missionUnComplete" :color="missionUnCompleteColors"></el-progress>
            <p>延期率</p>
          </div>
          <div style="border-top:1px solid #c0c4cc;float: left;width:100%">
            <div style="float: left;width: 20%">
              <p>{{ws}}</p>
              <p>未开始</p>
            </div>
            <div style="float: left;width: 20%">
              <p>{{doing}}</p>
              <p>进行中</p>
            </div>
            <div style="float: left;width: 20%">
              <p>{{complete}}</p>
              <p>已完成</p>
            </div>
            <div style="float: left;width: 20%">
              <p>{{all}}</p>
              <p>任务总数</p>
            </div>
            <div style="float: left;width: 20%">
              <p>{{postpone}}</p>
              <p>延期</p>
            </div>
          </div>
        </div>
      </el-col>
      <el-col :span="12">
        <div style="background-color: white;margin:0 20px;padding:10px 20px;text-align: center" class="clearfix">
          <p>任务类型分布</p>
          <div id="missionChart" style="width: 400px;height:280px;margin: 0 auto"></div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>


<script>
  import echarts from 'echarts'
  const axios = require('axios');
  export default {
    name: "overview",
    data() {
      return {
        principal_open : 0,
        start_open: 0,
        over_open: 0,
        description_open: 0,
        statusDes_open:0,
        status_open:0,
        type_open: 0,
        unit_open:0,
        representative_open:0,
        rouge_open:0,
        number_open:0,

        //任务类型分布
        charts: '',
        opinion:['项目目标','项目费用','项目任务'],

        opinionData:[
          {value:0, name:'项目目标'},
          {value:1, name:'项目费用'},
          {value:0, name:'项目任务'},
        ],

        //项目详情
        projectDetail: {
          principalId: "",
          principalName: "",
          principalHead: "",
          member: [],
          oldMember: [],
          creatorId:"",
          start: "",
          over: "",
          rouge: "",
          number: "",
          description: "",
          status: "",
          Scope: "",
          statusDes: "",
          type: "",
          unit: "",
          representative: "",
        },

        members: [],

        oldDes:"",
        oldStateDes:"",
        oldStart: "",
        oldOver: "",

        //任务数
        ws: 0,
        complete:0,
        doing:0,
        all:0,
        postpone:0,

        //判断是否能够有权限修改
        isUpdate: false,


        type:[{
          value: '内部项目',
          label: '内部项目'
        },{
          value: '外部项目',
          label: '外部项目'
        }],

        //可见范围
        scope: [{
          value: 0,
          label: '私有：只有加入的成员才能看见此项目'
        }, {
          value: 1,
          label: '公开：企业所有成员都可以看见此项目'
        }],

        //项目状态
        status:[{
          value: '正常',
          label: '正常'
        },{
          value: '有风险',
          label: '有风险'
        },
        {
          value: '失控',
          label: '失控'
        }],

        //完成率
        missionComplete: 0,
        missionCompleteColors: [
          {color: '#f56c6c', percentage: 20},
          {color: '#e6a23c', percentage: 40},
          {color: '#5cb87a', percentage: 60},
          {color: '#1989fa', percentage: 80},
          {color: '#6f7ad3', percentage: 100}
        ],
        //延期率
        missionUnComplete: 0,
        missionUnCompleteColors: [
          {color: '#f56c6c', percentage: 20},
          {color: '#e6a23c', percentage: 40},
          {color: '#5cb87a', percentage: 60},
          {color: '#1989fa', percentage: 80},
          {color: '#6f7ad3', percentage: 100}
        ],

        //日历
        pickerOptions: {
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }]
        }
      }
    },
    created() {
      this.$axios.all([
        axios.post('/getMemberMessage', {"enterprise_id": window.localStorage.getItem("enterprise_id")}),
        axios.post("/getProjectMessage",{"id":this.$route.params.id}),
      ]).then(this.$axios.spread((res1, res2) => {
        // console.log(res1);
        // console.log(res2);
        this.members = res1.data;

        this.$parent.projectName = res2.data.projectName;
        this.$parent.topStatus = res2.data.topStatus;
        this.$parent.creatorId = res2.data.creatorId;
        this.$parent.principalId = res2.data.principalId;

        this.opinionData[0].value = res2.data.target;
        this.opinionData[1].value = res2.data.cost;
        this.opinionData[2].value = res2.data.missionProject;
        this.drawPie("missionChart");
        if(res2.data.principalId == 0){
          this.projectDetail.principalId = "";
        }else{
          this.projectDetail.principalId = res2.data.principalId;
        }
        this.projectDetail.creatorId = res2.data.creatorId;
        this.projectDetail.principalName = res2.data.principalName;
        this.projectDetail.principalHead = res2.data.principalHead;
        this.projectDetail.start = res2.data.startDate;
        this.projectDetail.over = res2.data.overDate;
        this.projectDetail.status = res2.data.currentStatus;
        this.projectDetail.rouge = res2.data.rouge;
        let sArr = res2.data.membersId.split(",");
        let iArr = [];
        for(let i= 0; i < sArr.length;i++){
            iArr[i] = parseInt(sArr[i]);
        }
        this.projectDetail.member = iArr;
        this.projectDetail.oldMember = iArr;
        if(this.projectDetail.rouge == 0){
          this.projectDetail.Scope = "私有：只有加入的成员才能看见此项目";
        }else {
          this.projectDetail.Scope = "公开：企业所有成员都可以看见此项目";
        }
        this.projectDetail.number = res2.data.ProjectNumber;
        if(res2.data.unit == null){
          this.projectDetail.unit = "";
        }else{
          this.projectDetail.unit = res2.data.unit;
        }
        if(res2.data.representative == null){
          this.projectDetail.representative = "";
        }else{
          this.projectDetail.representative = res2.data.representative;
        }
        if(res2.data.projectType == null){
          this.projectDetail.type = "无";
        }else{
          this.projectDetail.type = res2.data.projectType;
        }
        if(res2.data.description == null){
          this.projectDetail.description = "无"
        }else{
          this.projectDetail.description = res2.data.description;
        }
        if(res2.data.StateDescription == null){
          this.projectDetail.statusDes = "无"
        }else{
          this.projectDetail.statusDes = res2.data.StateDescription;
        }
        this.missionComplete = res2.data.completeRate;
        this.missionUnComplete = res2.data.postponeRate;
        this.ws = res2.data.ws;
        this.complete = res2.data.complete;
        this.doing = res2.data.doing;
        this.all = res2.data.all;
        this.postpone = res2.data.postpone;

        if(res2.data.creatorId == window.localStorage.getItem("id") || res2.data.principalId == window.localStorage.getItem("id")){
          this.isUpdate = true;
        }
      }))

    },
    methods:{
      openPrincipal() {
        if(this.isUpdate){
          this.principal_open = 1;
          this.$nextTick(() => {
            this.$refs.principal.focus()
          })
        }
      },
      openStart() {
        if(this.isUpdate) {
          this.start_open = 1;
          this.oldStart = this.projectDetail.start;
          this.$nextTick(() => {
            this.$refs.start.focus()
          })
        }
      },
      openOver() {
        if(this.isUpdate) {
          this.over_open = 1;
          this.oldOver = this.projectDetail.over;
          this.$nextTick(() => {
            this.$refs.over.focus()
          })
        }
      },
      openDescription() {
        if(this.isUpdate) {
          this.description_open = 1;
          this.oldDes = this.projectDetail.description;
          this.$nextTick(() => {
            this.$refs.description.focus()
          })
        }
      },
      openStatusDes() {
        if(this.isUpdate) {
          this.statusDes_open = 1;
          this.oldStateDes = this.projectDetail.statusDes;
          this.$nextTick(() => {
            this.$refs.statusDes.focus()
          })
        }
      },
      openStatus() {
        if(this.isUpdate) {
          this.status_open = 1;
          this.$nextTick(() => {
            this.$refs.status.focus()
          })
        }
      },
      openRouge(){
        if(this.isUpdate) {
          this.rouge_open = 1;
          this.$nextTick(() => {
            this.$refs.rouge.focus()
          })
        }
      },
      openType() {
        if(this.isUpdate) {
          this.type_open = 1;
          this.$nextTick(() => {
            this.$refs.type.focus()
          })
        }
      },
      openUnit() {
        if(this.isUpdate) {
          this.unit_open = 1;
          this.$nextTick(() => {
            this.$refs.unit.focus()
          })
        }
      },
      openNumber() {
        if(this.isUpdate) {
          this.number_open = 1;
          this.$nextTick(() => {
            this.$refs.number.focus()
          })
        }
      },
      openRepresentative(){
        if(this.isUpdate) {
          this.representative_open = 1;
          this.$nextTick(() => {
            this.$refs.representative.focus()
          })
        }
      },

      drawPie(id){
        this.charts = echarts.init(document.getElementById(id))
        this.charts.setOption({
          tooltip: {
            trigger: 'item',
            formatter: '{a}<br/>{b}:{c} ({d}%)'
          },
          legend: {
            orient: 'vertical',
            x: 'left',
            data:this.opinion
          },
          series: [
            {
              name:'任务类型',
              type:'pie',
              radius:['50%','70%'],
              avoidLabelOverlap: false,
              label: {
                normal: {
                  show: false,
                  position: 'center'
                },
                emphasis: {
                  show: true,
                  textStyle: {
                    fontSize: '30',
                    fontWeight: 'blod'
                  }
                }
              },
              labelLine: {
                normal: {
                  show: false
                }
              },
              data:this.opinionData
            }
          ]
        })
      },
      //更改项目负责人
      updatePrincipal(id){
        let obj = {};
        obj = this.members.find((item)=>{//这里的userList就是上面遍历的数据源
          return item.value === id;//筛选出匹配数据
        });
        axios.post("/updateProjectPrincipal",{'principal_id':obj.value,"id":this.$route.params.id}).then(res => {
          if(res.data == 0){
            this.$notify.error({
              title: '错误',
              message: '修改失败'
            });
          }else {
            this.$notify({
              title: '成功',
              message: '修改成功',
              type: 'success'
            });
            this.principal_open = 0;
            // console.log(obj.label);//获取的item所有的值
            this.projectDetail.principalHead = obj.circleUrl;
            this.projectDetail.principalName = obj.label;
            // console.log(id);//获取的value
          }
        })


      },

      updateRouge(id){
        let obj = {};
        obj = this.scope.find((item)=>{//这里的userList就是上面遍历的数据源
          return item.value === id;//筛选出匹配数据
        });
        axios.post("/updateProjectRouge",{'rouge':obj.value,"id":this.$route.params.id}).then(res => {
            if(res.data == 0){
              this.$notify.error({
                title: '错误',
                message: '修改失败'
              });
            }else {
              this.$notify({
                title: '成功',
                message: '修改成功',
                type: 'success'
              });
              this.rouge_open = 0;
              // console.log(obj.label);//获取的item所有的值
              this.projectDetail.Scope = obj.label;
              // console.log(id);//获取的value
            }
        })
      },

      updateProjectName(){
        let reg = /^[a-zA-Z0-9]+$/
        if(this.projectDetail.number == ''){
          this.$message.error('项目编号不能为空');
        }else if(!reg.test(this.projectDetail.number)){
          this.$message.error('只能输入数字和字母');
        }else if(this.projectDetail.number.length > 20){
          this.$message.error('最多不能超过20字符');
        }else{
          axios.post("/updateProjectNumber",{"project_number":this.projectDetail.number,"id":this.$route.params.id,"enterprise_id":window.localStorage.getItem("enterprise_id")}).then(res =>{
            if(res.data == 2){
              this.$notify.error({
                title: '错误',
                message: '系统中已存在同样的项目编号'
              });
            }else if(res.data == 0){
              this.$notify.error({
                title: '错误',
                message: '修改项目编号失败'
              });
              this.number_open = 0;
            }else{
              this.$notify({
                title: '成功',
                message: '修改成功',
                type: 'success'
              });
              this.number_open = 0;
            }
          })
        }
      },

      updateStatusDes(){
        axios.post("/updateProjectStateDescription",{"state_description":this.projectDetail.statusDes,"id":this.$route.params.id}).then(res => {
          if(res.data == 0){
            this.$notify.error({
              title: '错误',
              message: '修改失败'
            });
          }else {
            this.$notify({
              title: '成功',
              message: '修改成功',
              type: 'success'
            });
          }
        })
        this.statusDes_open = 0
      },

      cancelStatusDes(){
        this.projectDetail.statusDes = this.oldStateDes;
        this.statusDes_open = 0
      },

      updateDes(){
        axios.post("/updateProjectDescription",{"description":this.projectDetail.description,"id":this.$route.params.id}).then(res => {
          if(res.data == 0){
            this.$notify.error({
              title: '错误',
              message: '修改失败'
            });
          }else {
            this.$notify({
              title: '成功',
              message: '修改成功',
              type: 'success'
            });
          }
        })
        this.description_open = 0
      },

      cancelDes(){
        this.projectDetail.description = this.oldDes;
        this.description_open = 0
      },

      updateRepresentative(){
        axios.post("/updateProjectCustomerRepresentative",{"customer_representative":this.projectDetail.representative,"id":this.$route.params.id}).then(res => {
          if(res.data == 0){
            this.$notify.error({
              title: '错误',
              message: '修改失败'
            });
          }else {
            this.$notify({
              title: '成功',
              message: '修改成功',
              type: 'success'
            });
            this.representative_open = 0;
          }
        })
      },

      updateUnit(){
        axios.post("/updateProjectCustomerUnit",{"customer_unit":this.projectDetail.unit,"id":this.$route.params.id}).then(res => {
          if(res.data == 0){
            this.$notify.error({
              title: '错误',
              message: '修改失败'
            });
          }else {
            this.$notify({
              title: '成功',
              message: '修改成功',
              type: 'success'
            });
            this.unit_open = 0;
          }
        })
      },

      updateType(){
        axios.post("/updateProjectType",{"project_type":this.projectDetail.type,"id":this.$route.params.id}).then(res => {
          if(res.data == 0){
            this.$notify.error({
              title: '错误',
              message: '修改失败'
            });
          }else {
            this.$notify({
              title: '成功',
              message: '修改成功',
              type: 'success'
            });
            this.type_open = 0;
          }
        })
      },

      updateStatus(){
        axios.post("/updateProjectState",{"state":this.projectDetail.status,"id":this.$route.params.id}).then(res => {
          if(res.data == 0){
            this.$notify.error({
              title: '错误',
              message: '修改失败'
            });
          }else {
            this.$notify({
              title: '成功',
              message: '修改成功',
              type: 'success'
            });
            this.status_open = 0;
          }
        })
      },

      updateStartDate(){
        if(Date.parse(this.projectDetail.start) > Date.parse(this.projectDetail.over)){
          this.$message.error("开始时间不能超过截止日期");
          this.projectDetail.start = this.oldStart;
        }else{
          axios.post("/updateStartDate",{"start_date":this.projectDetail.start,"id":this.$route.params.id}).then(res => {
            if(res.data == 0){
              this.$notify.error({
                title: '错误',
                message: '修改失败'
              });
            }else {
              this.$notify({
                title: '成功',
                message: '修改成功',
                type: 'success'
              });
              this.start_open = 0;
            }
          })
        }
      },

      updateOverDate(){
        if(Date.parse(this.projectDetail.start) > Date.parse(this.projectDetail.over)){
          this.$message.error("开始时间不能超过截止日期");
          this.projectDetail.over = this.oldOver;
        }else{
          axios.post("/updateOverDate",{"over_date":this.projectDetail.over,"id":this.$route.params.id}).then(res => {
            if(res.data == 0){
              this.$notify.error({
                title: '错误',
                message: '修改失败'
              });
            }else {
              this.$notify({
                title: '成功',
                message: '修改成功',
                type: 'success'
              });
              this.over_open = 0;
            }
          })
        }
      },

      updateMembers(members){
        axios.post("/updateProjectMembers",{"oldMembers":this.projectDetail.oldMember,"newMembers":members,"id":this.$route.params.id}).then(res => {
            if(res.data == 2){
              this.$notify.error({
                title: '错误',
                message: '该成员在项目中有参与任务，不能删除'
              });
              this.projectDetail.member = this.projectDetail.oldMember;
            }else if(res.data == 0){
              this.$notify.error({
                title: '错误',
                message: '修改失败'
              });
              this.projectDetail.member = this.projectDetail.oldMember;
            }else{
              this.$notify({
                title: '成功',
                message: '修改成功',
                type: 'success'
              });
              this.projectDetail.oldMember = members;
            }
        })
      },

      deleteProjects(){
        this.$confirm('删除项目后会移除到项目回收站，该项目的全部任务也会移除到回收站，确定要删除吗', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          axios.post("/deleteProject1",{"id":this.$route.params.id,"deleteId":window.localStorage.getItem("id")}).then(res =>{
            if(res.data == 0){
              this.$notify.error({
                title: '错误',
                message: '删除失败'
              });
            }else{
              this.$notify({
                title: '成功',
                message: '移除到回收站成功',
                type: 'success'
              });
              this.$emit("getMessage");
              this.$router.push("/user/projects/myMission/directed");
            }


          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      }
    }
  }
</script>

<style scoped>

</style>
